package com.iplay.service.notification.type.order.type;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

import com.iplay.component.im.OutgoingMessage;
import com.iplay.dto.ApiResponseMessage;
import com.iplay.service.notification.type.order.OrderMessage;
import com.iplay.service.notification.type.order.OrderMessageEntity;
import com.iplay.service.notification.type.order.OrderOutgoingMessage;
import com.iplay.service.order.RoleInOrder;
import com.iplay.service.user.UserContrains;

public class OrderCreatedMessage extends OrderMessageType {

	public OrderCreatedMessage(OrderMessageEntity entity) {
		super(entity);
	}

	@Override
	public List<OutgoingMessage> getOutgoingMessage() {
		OrderMessageEntity entity = this.getEntity();
		List<OutgoingMessage> messages = new LinkedList<>();
		if (!Objects.equals(entity.getCustomer(), entity.getRecommender()))
			messages.add(
					new OrderOutgoingMessage(entity.getRecommender(),
							new OrderMessage(entity.getOrderId(), RoleInOrder.RECOMMENDER, entity.getOrderStatusCategory(), 
									String.format(ApiResponseMessage.NEW_ORDER_FOR_RECOMMENDER, entity.getCustomer(),
											entity.getHotel()))));
		messages.add(new OrderOutgoingMessage(UserContrains.SUPER_ADMIN_USERNAME,
				new OrderMessage(entity.getOrderId(), String.format(ApiResponseMessage.NEW_ORDER_PAYMENT_FOR_ADMIN,
						entity.getCustomer(), entity.getHotel()))));
		return messages;
	}

}
